package org.restoran.util;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

/**
 * Embedded database Spring realisation as HSQLDB.
 * Id default try find schemaHSQL.sql and test_data.sql.
 *
 * url - jdbc:hsqldb:mem:'some db name'
 * password - nope password
 * username - "sa"
 *
 * Default db name is <code>test_db</code>
 */
public class EmbeddedDbSpringTest {

    public static final String TEST_DB_NAME = "test_db";

    private static EmbeddedDatabase db;

    @BeforeClass
    public static void setUpDatabase() {
        System.out.println("START UP Database!");
        db = new EmbeddedDatabaseBuilder().
                setType(EmbeddedDatabaseType.HSQL).
                setName(TEST_DB_NAME).
                addScript("schemaHSQL.sql").
                addScript("test_data.sql").
                build();
    }

    @AfterClass
    public static void shutDown() {
        System.out.println("SHUT DOWN Database!");
        if(db != null) {
            db.shutdown();
            db = null;
        }
    }

}
